function [ triangle ] = genTriangleStructure( tri, outer, inner, A, B )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
        triangle = struct();
         for i = 1:size(tri,1)
            v1 = totalBoundary(tri(i,1),:);
            v2 = totalBoundary(tri(i,2),:);
            v3 = totalBoundary(tri(i,3),:);
            triangle(i).Vertex1 = v1;
            triangle(i).Vertex2 = v2;
            triangle(i).Vertex3 = v3;
            V12 = [[v2(1) - v1(1), v2(2) - v1(2)],0];
            V21 =  - V12;
            V13 = [[v3(1) - v1(1), v3(2) - v1(2)],0];
            V31= - V13;
            V23 = [[v3(1) - v2(1), v3(2) - v2(2)],0];
            V32 =  - V23;
            triangle(i).Vector12 = V12; 
            triangle(i).Vector21 = V21;
            triangle(i).Vector13 = V13;
            triangle(i).Vector31 = V31;
            triangle(i).Vector23 = V23;
            triangle(i).Vector32 = V32;
            triangle(i).Angle213 = (180/pi)*(atan2(norm(cross(V12,V13)),dot(V12,V13)));
            triangle(i).Angle123 =  (180/pi)*(atan2(norm(cross(V21,V23)),dot(V21,V23)));
            triangle(i).Angle132 =  (180/pi)*(atan2(norm(cross(V31,V32)),dot(V31,V32)));
            triangle(i).L12 = norm(triangle(i).Vector12);
            triangle(i).L13 = norm(triangle(i).Vector13);
            triangle(i).L23 = norm(triangle(i).Vector23);
            
            %Determine the boundary that each vertex is on
           
               %V1
               if ismember( v1, side1,'rows')&& ismember( v1, side2,'rows')
                     triangle(i).V1Side = 3;
               elseif  ismember( v1, side1,'rows')
                   triangle(i).V1Side = 1;
               elseif ismember( v1, side2,'rows')
                   triangle(i).V1Side = 2;
               elseif ismember( v1, inner,'rows')
                   triangle(i).V1Side = 0;
               else
                      triangle(i).V1Side = 4;
               end

               %V2
               if ismember( v2, side1,'rows')&& ismember( v2, side2,'rows')
                     triangle(i).V2Side = 3;
               elseif  ismember( v2, side1,'rows')
                   triangle(i).V2Side = 1;
                elseif ismember( v2, side2,'rows')
                   triangle(i).V2Side = 2;
                elseif ismember( v2, inner,'rows')
                   triangle(i).V2Side = 0;
                else
                      triangle(i).V2Side = 4;
                end

               %V3
               if ismember( v3, side1,'rows')&& ismember( v3, side2,'rows')
                     triangle(i).V3Side = 3;
               elseif  ismember( v3, side1,'rows')
                   triangle(i).V3Side = 1;
                elseif ismember( v3, side2,'rows')
                   triangle(i).V3Side = 2;
                elseif ismember( v3, inner,'rows')
                   triangle(i).V3Side = 0;
                else
                    triangle(i).V3Side = 4;
                end
            
                %Determine if the triangle is an external triangle
                 if   (triangle(i).V1Side == triangle(i).V2Side...
                       && triangle(i).V2Side == triangle(i).V3Side)...
                   ||...
                      (triangle(i).V1Side == triangle(i).V2Side...
                       && triangle(i).V3Side == 3 )...
                   ||...
                       (triangle(i).V1Side == triangle(i).V3Side...
                       && triangle(i).V2Side == 3 )...
                    ||...
                       (triangle(i).V2Side == triangle(i).V3Side...
                       && triangle(i).V1Side == 3 )...
                
                      triangle(i).IsExternal = 1;
                 else
                     triangle(i).IsExternal = 0;
                 end
             
                 %Determine if it is an end triangle
                 if triangle(i).V1Side == 3 ...
                     || triangle(i).V2Side == 3 ...
                     || triangle(i).V3Side == 3
                        triangle(i).IsEnd = 1;
                 else
                     triangle(i).IsEnd = 0;
                 end
             
                 %Determine the edge along the boundary for right triangles
                 if ~triangle(i).IsExternal && ~triangle(i).IsEnd
                   if triangle(i).V1Side == triangle(i).V2Side
                       triangle(i).IsRightTriangle = 1;
                       triangle(i).BoundaryEdge = [1,2];
                       if triangle(i).L13 < triangle(i).L23
                          triangle(i).RightEdge = [1,3];
                          a  = triangle(i).Vertex1;
                          b  = triangle(i).Vertex3;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                       else
                          triangle(i).RightEdge = [2,3];
                          a  = triangle(i).Vertex2;
                          b  = triangle(i).Vertex3;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                       end
                   elseif triangle(i).V1Side == triangle(i).V3Side
                       triangle(i).IsRightTriangle = 1;
                       triangle(i).BoundaryEdge = [1,3];
                       if triangle(i).L12 < triangle(i).L23
                          triangle(i).RightEdge = [1,2];
                          a  = triangle(i).Vertex1;
                          b  = triangle(i).Vertex2;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                       else
                          triangle(i).RightEdge = [3,2];
                          a  = triangle(i).Vertex3;
                          b  = triangle(i).Vertex2;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                        end
                   elseif triangle(i).V2Side == triangle(i).V3Side
                       triangle(i).BoundaryEdge = [2,3];
                       triangle(i).IsRightTriangle = 1;
                       if triangle(i).L12 < triangle(i).L13
                          triangle(i).RightEdge = [2,1];
                          a  = triangle(i).Vertex2;
                          b  = triangle(i).Vertex1;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                       else
                          triangle(i).RightEdge = [3,1];
                          a  = triangle(i).Vertex3;
                          b  = triangle(i).Vertex1;
                          triangle(i).Midpoint = [(a(1)+ b(1))/2,(a(2)+b(2))/2];
                       end 
                       
                   else
                       triangle(i).BoundaryEdge = [0,0]; 
                       triangle(i).IsRightTriangle = 0;
                       triangle(i).Midpoint = [0,0];
                   end
                 else
                   triangle(i).BoundaryEdge = [0,0]; 
                   triangle(i).IsRightTriangle = 0;
                   triangle(i).Midpoint = [0,0];
                 end    

                        
           
                  
            if    triangle(i).V1Side == 4 ...
               || triangle(i).V2Side == 4 ...
               || triangle(i).V3Side == 4
                    triangle(i).IsInternal = 1;
            else
                triangle(i).IsInternal = 0;
            end
        
         
         end

end

